/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.ues21.tcs.ecommerce2011.mvc.service.impl;

import edu.ues21.tcs.ecommerce2011.mvc.dao.AdministradorDAO;
import edu.ues21.tcs.ecommerce2011.mvc.dao.UsuarioDAO;
import edu.ues21.tcs.ecommerce2011.mvc.model.AbstractUser;
import edu.ues21.tcs.ecommerce2011.mvc.model.Administrador;
import edu.ues21.tcs.ecommerce2011.mvc.model.Usuario;
import edu.ues21.tcs.ecommerce2011.mvc.service.LoginService;

/**
 *
 * @author vascordoba
 */
public class LoginServiceImpl implements LoginService{

    private UsuarioDAO userDao;
    private AdministradorDAO adminDao;

    public LoginServiceImpl(UsuarioDAO userDao,AdministradorDAO adminDao){
        this.userDao=userDao;
        this.adminDao=adminDao;
    }

    @Override
    public AbstractUser login(String user,String pass) throws Exception{
        Usuario retUser=null;
        Administrador retAdmin=null;
        retUser=userDao.getUsuario(user);
        if(retUser!=null && pass.equals(retUser.getPassword())){
            return retUser;
        }
        else{
            retAdmin=adminDao.getAdministrador(user);
            if(retAdmin!=null && pass.equals(retAdmin.getPassword())){
                return retAdmin;
            }
        }
        return null;
    }

}
